import java.util.Arrays;

public class Leet63 {
    public static void main(String[] args) {
        System.out.println(uniquePathsWithObstacles(new int[][]{{0,0,0},{0,1,0},{0,0,0}}));
    }
    static public int uniquePathsWithObstacles(int[][] obstacleGrid) {
        if (obstacleGrid[0][0]==1)
            return 0;
//        int[][] dp = new int[obstacleGrid.length+1][obstacleGrid.length]
        boolean flag = false;
        for (int i = 0; i < obstacleGrid.length; i++) {
            if (obstacleGrid[i][0]==1){
                obstacleGrid[i][0]=0;
                flag = true;
            }
            obstacleGrid[i][0] = flag?0:1;
        }
        flag = false;
        for (int i = 1; i < obstacleGrid[0].length; i++) {
            if (obstacleGrid[0][i]==1){
                obstacleGrid[0][i]=0;
                flag = true;
            }
            obstacleGrid[0][i] = flag?0:1;
        }
        for (int i = 1; i < obstacleGrid.length; i++) {
            for (int j = 1; j < obstacleGrid[0].length; j++) {
                if (obstacleGrid[i][j]==1){
                    obstacleGrid[i][j]=0;
                    continue;
                }
                obstacleGrid[i][j] = obstacleGrid[i-1][j]+obstacleGrid[i][j-1];
            }
        }
        return obstacleGrid[obstacleGrid.length-1][obstacleGrid[0].length-1];
    }
}
